// ==UserScript==
// @name           ccplus | Dev code
// @namespace      t2t2
// @include        http://www.casualcollective.com/*
// @include        http://casualcollective.com/*
// ==/UserScript==
defaultURL = 'http://ccplus.googlecode.com/svn/trunk/live/ccplus.js'
devURL = 'http://ccplus.googlecode.com/svn/trunk/dev/ccplus.js'
fileURL = GM_getValue('fileURL', defaultURL)

GM_registerMenuCommand('CC+ | Use file | '+(fileURL == defaultURL ? 'LIVE' : (fileURL == devURL ? 'DEV' : 'CUSTOM')), switchFile)
var settings;
function switchFile() {
	settings = window.open('about:blank', 'ccplusconfig', 'width=400,height=300')
	settings.addEventListener("load", function() {
		if(fileURL == defaultURL) {
			var current = '<a href="'+defaultURL+'">LIVE File</a>'
		} else if(fileURL == devURL) {
			var current = '<a href="'+devURL+'">DEV File</a>'
		} else {
			var current = '<a href="'+fileURL+'">'+fileURL+'</a>'
		}
		settings.document.body.innerHTML = 'Currently using:<br />'+current+'<br /><br /><span id="switchLiveFeed">Set to Live feed</span><br /><span id="switchDevFeed">Set to Dev feed</span><br /><span id="switchCustomFeed">Set to Custom feed</span>'
		settings.document.getElementById('switchLiveFeed').addEventListener('click', setFeed, false)
		settings.document.getElementById('switchDevFeed').addEventListener('click', setFeed, false)
		settings.document.getElementById('switchCustomFeed').addEventListener('click', setFeed, false)
	}, false);
}
function setFeed() {
	if(this.id == 'switchLiveFeed') {
		GM_setValue('fileURL', defaultURL)
	} else if(this.id == 'switchDevFeed') {
		GM_setValue('fileURL', devURL)
	} else if(this.id == 'switchCustomFeed') {
		GM_setValue('fileURL', prompt('Enter the URL of the file', ''))
	}
	settings.close()
	window.location.reload()
}

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = fileURL;
document.body.appendChild(script);
